import { BASE_URL } from "@/baseUrl";

import type { API } from '@/backend/typings.d';
import {request} from "@/utils/requestWrapper";

/** 添加商品SKU POST /api/product_sku/add */
export async function addProductSkuUsingPost(
  body: API.ProductSKUAddRequest,
  options?: { [key: string]: any }
) {
  return new Promise<API.BaseResponseLong_>((resolve, reject) => {
    uni.request({
      url: BASE_URL + "/api/product_sku/add",
      method: "POST",
      header: {
        "Content-Type": "application/json",
      },
      data: body,
      success: (res) => {
        resolve(res.data as API.BaseResponseLong_);
      },
      fail: (err) => {
        reject(err);
      },
      ...(options || {}),
    });
  });
}

/** 删除商品SKU POST /api/product_sku/delete */
export async function deleteProductSkuUsingPost(
  body: API.DeleteRequest,
  options?: { [key: string]: any }
) {
  return new Promise<API.BaseResponseBoolean_>((resolve, reject) => {
    uni.request({
      url: BASE_URL + "/api/product_sku/delete",
      method: "POST",
      header: {
        "Content-Type": "application/json",
      },
      data: body,
      success: (res) => {
        resolve(res.data as API.BaseResponseBoolean_);
      },
      fail: (err) => {
        reject(err);
      },
      ...(options || {}),
    });
  });
}

/** 获取商品SKU详情 GET /api/product_sku/get/vo */
export async function getProductSkuVoByIdUsingGet(
  params: API.getProductSKUVOByIdUsingGETParams,
  options?: { [key: string]: any }
) {
  return new Promise<API.BaseResponseProductSKUVO_>((resolve, reject) => {
    uni.request({
      url: BASE_URL + "/api/product_sku/get/vo",
      method: "GET",
      data: params,
      success: (res) => {
        resolve(res.data as API.BaseResponseProductSKUVO_);
      },
      fail: (err) => {
        reject(err);
      },
      ...(options || {}),
    });
  });
}

/** 分页获取商品SKU列表 POST /api/product_sku/list/page/vo */
export async function listProductSkuVoByPageUsingPost(
  body: API.ProductSKUQueryRequest,
  options?: { [key: string]: any }
) {
  return new Promise<API.BaseResponsePageProductSKUVO_>((resolve, reject) => {
    uni.request({
      url: BASE_URL + "/api/product_sku/list/page/vo",
      method: "POST",
      header: {
        "Content-Type": "application/json",
      },
      data: body,
      success: (res) => {
        resolve(res.data as API.BaseResponsePageProductSKUVO_);
      },
      fail: (err) => {
        reject(err);
      },
      ...(options || {}),
    });
  });
}

/** 更新商品SKU POST /api/product_sku/update */
export async function updateProductSkuUsingPost(
  body: API.ProductSKUUpdateRequest,
  options?: { [key: string]: any }
) {
  return new Promise<API.BaseResponseBoolean_>((resolve, reject) => {
    uni.request({
      url: BASE_URL + "/api/product_sku/update",
      method: "POST",
      header: {
        "Content-Type": "application/json",
      },
      data: body,
      success: (res) => {
        resolve(res.data as API.BaseResponseBoolean_);
      },
      fail: (err) => {
        reject(err);
      },
      ...(options || {}),
    });
  });
}

/** 根据商品id获取规格列表 GET /api/product_sku/list/vo */
// export async function listProductSkuVoByProductIdUsingGet(
//   params: API.listProductSkuVOByProductIdUsingGETParams,
//   options?: { [key: string]: any }
// ) {
//   return request<API.BaseResponseListProductSkuVO_>({
//     url: "/api/product_sku/list/vo",
//     method: "GET",
//     params,
//     ...(options || {})
//   });
// }